class Solution
{
public:
    int maxHeightOfTriangle(int red, int blue)
    {
        int r = red, b = blue;
        int i = 0;
        while (true)
        {
            if (i & 1)
            {
                if (i + 1 <= red)
                {
                    red -= i + 1;
                }
                else
                {
                    break;
                }
            }
            else
            {
                if (i + 1 <= blue)
                {
                    blue -= i + 1;
                }
                else
                {
                    break;
                }
            }
            ++i;
        }
        red = r;
        blue = b;
        int j = 0;
        while (true)
        {
            if (j & 1)
            {
                if (j + 1 <= blue)
                {
                    blue -= j + 1;
                }
                else
                {
                    break;
                }
            }
            else
            {
                if (j + 1 <= red)
                {
                    red -= j + 1;
                }
                else
                {
                    break;
                }
            }
            ++j;
        }
        return max(i, j);
    }
};